import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Interface extends JFrame {

	private static final long serialVersionUID = 5520644475993052526L;
	public static int input = 0;
	public static boolean proceed = true;

	public Interface() {
		super("GUI Player 1");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JButton button1 = new JButton("Play Card 1");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C12hide == false) {
					Card.playCard12();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C12hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button2 = new JButton("Play Card 2");
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C11hide == false) {

					Card.playCard11();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C11hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button3 = new JButton("Play Card 3");
		button3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C10hide == false) {

					Card.playCard10();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C10hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button4 = new JButton("Play Card 4");
		button4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C9hide == false) {

					Card.playCard9();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C9hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button5 = new JButton("Play Card 5");
		button5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C8hide == false) {

					Card.playCard8();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C8hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});
		JButton button6 = new JButton("Play Card 6");
		button6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String x = JOptionPane
						.showInputDialog("Which stone do you wish to play to? (1-9)");

				if (x.length() != 0) {
					input = Integer.parseInt(x);
				} else {
				}

				proceed();

				if (input >= 1 && input <= 9 && x.length() != 0
						&& proceed == true && Board.C7hide == false) {

					Card.playCard7();
					Card.hidePlayer();
					JOptionPane.showMessageDialog(rootPane, "Player 2's turn");
					dispose();
					Compare.main(null);
					Interface2.main(null);
					Card.showDealer();
				} else if (proceed == false) {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Stone has 3 cards played");
					proceed = true;
				} else if (Board.C7hide == true) {
					JOptionPane.showMessageDialog(rootPane,
							"Card has been played. Don't cheat.");
				} else {
					JOptionPane.showMessageDialog(rootPane,
							"Invalid. Enter a Stone between 1-9.");
				}
			}
		});

		JToolBar bar = new JToolBar(null, JToolBar.VERTICAL);
		JMenu label = new JMenu(Menu.Player1 + "'s hand (Card 1-6)");
		label.setForeground(Color.BLUE);
		bar.add(label);
		bar.add(button1);
		bar.add(button2);
		bar.add(button3);
		bar.add(button4);
		bar.add(button5);
		bar.add(button6);
		bar.setBackground(Color.YELLOW);
		JPanel pane = new JPanel();
		pane.add("North", bar);
		setContentPane(pane);
	}

	public static void proceed() {
		if (input == 1 && Board.S1cap == false) {
			proceed = false;
		}
		if (input == 2 && Board.S2cap == false) {
			proceed = false;
		}
		if (input == 3 && Board.S3cap == false) {
			proceed = false;
		}
		if (input == 4 && Board.S4cap == false) {
			proceed = false;
		}
		if (input == 5 && Board.S5cap == false) {
			proceed = false;
		}
		if (input == 6 && Board.S6cap == false) {
			proceed = false;
		}
		if (input == 7 && Board.S7cap == false) {
			proceed = false;
		}
		if (input == 8 && Board.S8cap == false) {
			proceed = false;
		}
		if (input == 9 && Board.S9cap == false) {
			proceed = false;
		}
	}

	public static void main(String[] arguments) {
		Interface frame = new Interface();
		frame.setLocation(955, 505);
		frame.pack();
		frame.setVisible(true);
	}
}